package com.by.controller.purchase;

import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.controller.BaseController;
import com.by.condition.purchase.PurchaseCondition;
import com.by.entity.purchase.Purchase;
import com.by.service.purchase.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/purchase")
public class PurchaseController extends BaseController {

    @Autowired
    PurchaseService purchaseService;

    @PostMapping("/save")
    public ResultBean save(@RequestBody Purchase purchase) {
        boolean rs = purchaseService.save(purchase);
        return rs ? success("保存成功") : fail("保存失败");
    }

    @PostMapping("/query")
    public ResultBean query(@RequestBody PurchaseCondition condition) {
        PageBean bean = purchaseService.query(condition);
        return success("采购申请列表", bean);
    }

    @GetMapping("/get")
    public ResultBean get(String id){
        Purchase purchase=purchaseService.queryDetail(id);
        return success("采购申请详情",purchase);
    }
}
